#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

#define BUF_SIZE 1024

int main(){
  mkfifo("ComFIFO", 0664);
  int wfd = open("ComFIFO", O_WRONLY);
  if(wfd < 0){
    perror("open");
    exit(-1);
  }
  char buffer[BUF_SIZE];
  int len;
  while(1){
    memset(buffer, 0, BUF_SIZE);
    if(fgets(buffer, BUF_SIZE, stdin) == NULL){
      perror("fgets");
    }
    len = strlen(buffer);
    if(write(wfd, buffer, len) != len){
      perror("write");
    }
    fflush(stdin);
    fflush(stdout);
  }
  close(wfd);
  unlink("ComFIFO");
  return 0;
}
